<?php
namespace Android\Controller;


class NoticeController extends BaseController {

    public function getNoticeList () {

        $student_id = I ('request.student_id',null);
        if (empty($student_id))
            $this->out($this->fail, 'Empty parameter');

        $page = I ('request.page',1);
        $rows = I ('request.rows',10);
        $limit = ($page-1)*$rows.','.$rows;

        $Notice = D ('Notice');

        $where = "student_ids = {$student_id} OR student_ids LIKE '%,{$student_id},%' OR student_ids LIKE '{$student_id},%' OR student_ids LIKE '%,{$student_id}' AND term_id = {$this->term['id']}";
        $noticeArr = $Notice->getNoticeByWhere($where,$limit);

        if (empty($noticeArr))
            $this->out($this->fail, '没有任何通知');

        // 获取老师信息
        $Teacher = D ('Teacher');
        foreach ($noticeArr as $k=>$v) {
            $noticeArr[$k]['teacher_name'] = $Teacher->getTeacherName($v['teacher_id']);
        }

        $page_index = $page;
        $page_size = $rows;
        $amount = $Notice->where($where)->count();
        $page_total = intval(ceil($amount/$page_size));

        $value = array(
            'page_index' => $page_index,
            'page_size' => $page_size,
            'page_total' => $page_total,
            'amount' => intval($amount),
            'data' => $noticeArr
        );

        $this->out($this->success,'Success', $value);
    }



    public function getNoticeDetail () {

        $notice_id = I ('request.notice_id',null);
        if (empty($notice_id))
            $this->out($this->fail, 'Empty parameter');

        $notice = D ('Notice')->getNoticeDetail($notice_id);
        if (empty($notice))
            $this->out($this->fail,'没有该通知');
        $this->out($this->success,'Success',$notice);
    }

}